package com.etc.dao;

import com.etc.entity.Cinema;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Repository
public interface CinemaDao extends JpaRepository<Cinema,Integer>,JpaSpecificationExecutor<Cinema>,Serializable {

    /**
     * 根据影厅名模糊查询
     * @param query
     * @param pageable
     * @return
     */
    @Query("select c from  Cinema c where c.cname like %?1% group by c.cname order by c.cid")
    Page<Cinema> findByLike(String query, Pageable pageable);

    /**
     * 查出所有的影厅名
     * @return List<Cinema>
     */
    @Query("select c from  Cinema c group by c.cname order by c.cname")
    List<Cinema> findAllcname();


    /**
     * 根据影厅名查影厅数据
     * @param cname
     * @return List<Cinema>
     */
     List<Cinema> findByCname(String cname);

    /**
     * 查询 某个电影  在某天的 所有场次
     * @param mid
     * @param startDate
     * @return
     */
    @Query("SELECT c FROM Cinema c WHERE DATE(mstartime) = ?2 AND mid=?1 AND mstartime > NOW()")
    List<Cinema> findByMidAndMstartime(Integer mid, Date startDate);
}